package com.yiyi.credit.manage.sso.mapper;

import com.yiyi.credit.manage.sso.common.constants.PaginationConstants;
import com.yiyi.credit.manage.sso.common.page.PageUtils;
import org.apache.commons.lang.StringUtils;

import java.util.Map;


public class ShopSqlProvider {

    //查询表
    private String fromInfo = " FROM shop s LEFT JOIN sys_user s2 ON s.`creater` = s2.`id` LEFT JOIN sys_user s3 ON s.`updater` = s3.`id`";


    public String queryForPage(Map<String, Object> paramMap) {
        //查询字段
        String selectFiled = "s.id,s.sname,s.province,s.city,s.creater,s2.user_name createrName,s3.user_name updaterName,s.updater,s.create_time createTime,s.update_time updateTime ";

        return PageUtils.getPageCommonSql(selectFiled, fromInfo,  whereSql(paramMap), "s.id")
                + PaginationConstants.LIMIT_SQL;
    }


    public String queryCount(Map<String, Object> paramMap) {
        //查询条数
        String countFiled = " count(s.id) count ";
        return PageUtils.getPageCountSql(countFiled, fromInfo,  whereSql(paramMap));
    }



    private String whereSql(Map<String, Object> paramMap) {
        StringBuilder sqlBuilder = new StringBuilder();
        sqlBuilder.append(" WHERE 1 = 1 ");
        if (null != paramMap.get("sname")
                && StringUtils.isNotBlank(String.valueOf(paramMap.get("sname")))) {
            sqlBuilder.append(" AND s.sname = #{sname} ");
        }
        return sqlBuilder.toString();
    }

}
